<template>
  <div>
    <van-tabs v-model="active" sticky @click="dianji(active - 1)">
      <van-tab v-for="(item, index) in arr" :title="item.a" :key="index">
        <div>
          <router-view></router-view>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
export default {
  name: "MyDingdan",
  data() {
    return {
      active: 0,
      arr: [
        { name: "quanbu", a: "全部" },
        { name: "daizhifu", a: "待支付" },
        { name: "daifahuo", a: "待发货" },
        { name: "daishouhuo", a: "待收货" },
        { name: "yiquxiao", a: "已取消" },
      ],
    };
  },
  methods: {
    dianji(index) {
      // index=-1 全部
      if (index == -1) {
        this.$store.state.wddsstatys = -1;
        // this.active = 0;
        this.$router
          .replace({
            name: "quanbu",
          })
          .catch((err) => {});
      } else {
        this.$store.state.wddsstatys = index;
        this.active = index + 1;
        this.$router
          .replace({
            name: "ddxx",
          })
          .catch((err) => {});
      }
    },
  },
  mounted() {
    console.log("this.name:",this.name);
    if (this.name) {
      if (this.name == "quanbu") {
        this.$router
          .replace({
            name: "quanbu",
          })
          .then((res) => {
            this.active = 0;
          })
          .catch((err) => {});
      } else {
        this.$router
          .replace({
            name: "ddxx",
          })
          .then((res) => {
            this.active = +this.$store.state.wddsstatys + 1;
          })
          .catch((err) => {});
      }
    } else {
      // 刷新后直接回到全部订单页面
      this.$router
        .replace({
          name: "quanbu",
        })
        .then((res) => {
          this.active = 0;
        })
        .catch((err) => {});
    }
  },
  props: ["name"],
};
</script>

<style>
</style>